/**
 * @file WordQuery.hpp
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2022-04-05
 *
 * @copyright Copyright (c) 2022
 *
 */

#pragma once

#include "Configuration.hpp"
#include "WebPage.hpp"
#include "WordSegmentation.hpp"

#include <map>
#include <set>
#include <string>
#include <vector>

using std::make_pair;
using std::map;
using std::pair;
using std::set;
using std::string;
using std::unordered_map;
using std::vector;
using namespace wd;

namespace wd
{

class WordQuery
{
  public:
    WordQuery(Configuration &conf);

    string doQuery(const string &str);

  private:
    void loadLibrary();

    vector<double> getQueryWordsWeightVector(vector<string> &queryWords);
    bool executeQuery(const vector<string> &queryWords, vector<pair<int, vector<double>>> &resultVec);
    string createJson(vector<int> &docIdVec, const vector<string> &queryWords);
    string returnNoAnswer();

  private:
    WordSegmentation _jieba;
    Configuration &_conf;
    unordered_map<int, WebPage> _pageLib;
    unordered_map<int, pair<int, int>> _offsetLib;
    unordered_map<string, set<pair<int, double>>> _invertIndexTable;
};

} // namespace wd
